﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using A2DFramework.MVCFramework.Descriptors;
using A2DFramework.MVCFramework.HttpHandlers;

namespace A2DFramework.MVCFramework.Factories
{
    public class MvcHandlerFactory:IHttpHandlerFactory
    {
        public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            ControllerDescriptor controllerDescriptor = ControllerFactory.Resolve(context);
            if (controllerDescriptor == null)
                throw new Exception("没有找到相应的Controller");

            MethodDescriptor methodDescriptor = MethodFactory.Resolve(controllerDescriptor, context);
            if (methodDescriptor == null)
                throw new Exception("没有找到相应的调用方法");

            IHttpHandler handler = new JsonHttpHandler(controllerDescriptor, methodDescriptor);
            return handler;
        }

        public void ReleaseHandler(IHttpHandler handler)
        {
            throw new NotImplementedException();
        }
    }
}
